package org.example.myleet.rosalind.eval;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
//        solution.solve(10, "AG", "0.25 0.5 0.75");
        solution.solve(821774, "TAAGATCAG", "0.000 0.125 0.171 0.233 0.271 0.347 0.412 0.486 0.542 0.586 0.666 0.700 0.803 0.832 0.919 1.000");
    }

    public void solve(int n, String seq, String gcContentArrStr) {
        int at = 0, cg = 0;
        for (int i = 0; i < seq.length(); ++i) {
            char c = seq.charAt(i);
            if (c == 'A' || c == 'T') {
                ++at;
            } else if (c == 'C' || c == 'G') {
                ++cg;
            }
        }
        String[] gcContentStrArr = gcContentArrStr.split(" ");
        for (String gcContentStr : gcContentStrArr) {
            BigDecimal pyrimidinePr = (new BigDecimal(gcContentStr)).divide(BigDecimal.valueOf(2), 10, RoundingMode.HALF_UP);
            BigDecimal purinePr = BigDecimal.valueOf(0.5).subtract(pyrimidinePr);
            BigDecimal sequencePr = BigDecimal.ONE;
            for (int i = 0; i < at; ++i) {
                sequencePr = sequencePr.multiply(purinePr);
            }
            for (int i = 0; i < cg; ++i) {
                sequencePr = sequencePr.multiply(pyrimidinePr);
            }
            BigDecimal appearanceEx = sequencePr.multiply(BigDecimal.valueOf(n - 1));
            System.out.printf("%s ", appearanceEx.setScale(3, RoundingMode.HALF_UP));
        }
    }
}
